package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.View;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemGuideUserTxtBinding;
import com.jwdf.uda.databinding.ViewRecommendItemTopBinding;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.GuideDetailItem;
import com.jwdf.uda.utils.DateUtils;
import com.jwdf.uda.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 类说明：
 */
public class GuideUserTxtViewHolder extends AbsViewHolder<GuideDetailItem> {
    private ItemGuideUserTxtBinding mItemBinding;

    public GuideUserTxtViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
        mItemBinding.topLayout.tvName.setOnClickListener(this);
        mItemBinding.topLayout.ivHeader.setOnClickListener(this);
    }
    @Override
    protected void onBindView(GuideDetailItem item) {
        PbBean.PbGuideSimple guideInfo = item.guideSimple;
        if (guideInfo == null) return;
        mItemBinding.setIsDesigner(guideInfo.getUserInfo().getIsDesigner());
        mItemBinding.tvTime.setVisibility(View.VISIBLE);
        mItemBinding.tvTime.setText(DateUtils.getFriendlyTime(guideInfo.getTime()));
        onBindCommonView(mItemBinding.topLayout, guideInfo);
//
//        if (item.userShow != null && item.userShow.getId() > 0) {
//            mItemBinding.gapLayout.setVisibility(View.GONE);
//        } else {
//            mItemBinding.gapLayout.setVisibility(View.VISIBLE);
//        }
    }
    static void onBindCommonView(ViewRecommendItemTopBinding topLayout, PbBean.PbGuideSimple item) {
        topLayout.tvName.setText(item.getUserInfo().getNickname());
        if(StringUtils.isNullEmpty(item.getContent())) {
            topLayout.tvContent.setVisibility(View.GONE);
        } else {
            topLayout.tvContent.setVisibility(View.VISIBLE);
            topLayout.tvContent.setText(item.getContent());
        }

        topLayout.ivIsDesigner.setVisibility(item.getUserInfo().getIsDesigner()?View.VISIBLE:View.GONE);

        switch (item.getStatus()) {
            case GUIDE_STATUS_NONE:
                topLayout.tvStatus.setText("无状态");
                break;
            case GUIDE_STATUS_WAIT:
                topLayout.tvStatus.setText("待响应");
                break;
            case GUIDE_STATUS_UNDERWAY:
                topLayout.tvStatus.setText("服务中");
                break;
            case GUIDE_STATUS_DESIGNER_FINISHED:
                topLayout.tvStatus.setText("完成待确认");
                break;
            case GUIDE_STATUS_BACK:
                topLayout.tvStatus.setText("进行中");
                break;
            case GUIDE_STATUS_EVALUATION:
                topLayout.tvStatus.setText("强制结束");
                break;
            case GUIDE_STATUS_FINISHED:
                topLayout.tvStatus.setText("完成已确认");
                break;
            case GUIDE_STATUS_CANCEL:
                topLayout.tvStatus.setText("已取消");
                break;
        }

        topLayout.tvIntro.setVisibility(TextUtils.isEmpty(StringUtils.filterNullAndTrim(item.getUserInfo().getIntroduction()))?View.GONE:View.VISIBLE);
        topLayout.tvIntro.setText(item.getUserInfo().getIntroduction());
        ImageLoader.getInstance().displayImage(item.getUserInfo().getAvatar().getUrl(), topLayout.ivHeader);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ivHeader:
            case R.id.tvName:
                if(item.guideSimple != null){
                    UserInfoActivity.start(v.getContext(), item.guideSimple.getUserInfo().getUserId(), item.guideSimple.getUserInfo().getIsDesigner());
                }
                break;
        }
    }
}
